package synchro;

import java.io.*;
import java.util.Date;

/**
 * @author DELL
 * @create 2017-09-22 17:40
 */
public class LogFile2 {

    private File f;

    public LogFile2(File f) throws IOException {
        this.f = f;

    }

    /**
     * 是用局部变量而不是字段来代替同步
     * @param message
     * @throws IOException
     */
    public void writeEntry(String message) throws IOException {
        Date d = new Date();
        FileWriter fw = new FileWriter(f, true);
        Writer out = new BufferedWriter(fw);
        out.write(message + ":" + d.toString());
        out.write('\t');
        out.write(message);
        out.write("\r\n");
        out.flush();
        out.close();
    }
}
